<template>
  <div id="mainbox"></div>
</template>

<script>
import * as echarts from "echarts";
export default {
  mounted() {
    //基于准备好的dom，初始化echarts实例
    this.myChart = echarts.init(document.getElementById("mainbox"));
    //绘制图标
    this.setEcharts();
  },
  methods: {
    setEcharts(data) {
      //绘制图表
      this.myChart.setOption({
        //背景色
        backgroundColor: "#2c343c",
        title: {//图表的标题
          text: "销量",
          left: "center",
          top: 20,
          textStyle: {
            color: "#ccc",
          },
        },
        tooltip: {//提示
          trigger: "item",
        },
        visualMap: {//饼颜色大小
          show: false,
          min: 80,
          max: 600,
          inRange: {
            colorLightness: [0, 1],
          },
        },
        series: [//数据系列
          {
            type: "pie",
            radius: "55%",
            center: ["50%", "50%"],
            data: [
              { value: 335, name: "衬衫" },
              { value: 310, name: "羊毛衫" },
              { value: 274, name: "雪纺衫" },
              { value: 235, name: "裤子" },
              { value: 380, name: "高跟鞋" },
              { value: 210, name: "袜子" },
            ].sort(function (a, b) {
              return a.value - b.value;
            }),
            roseType: "radius",//不规则排序
            animationType: "scale",
            animationEasing: "elasticOut",
            animationDelay: function (idx) {
              return Math.random() * 200;
            },
          },
        ],
      });
    },
  },
};
</script>

<style lang="scss">
#mainbox {
    width: 550px;
    height: 350px;
  }
</style>